<?php
namespace Common\Model;
use Think\Model;

class MoodModel extends Model {
	private $_db ='';
	public function __construct(){
		$this->_db = M('mood');
	}
	
	public function insert($data = array()){
		if(!$data || !is_array($data)){
			return 0;
		}
		return $this->_db->add($data);
	}
	
	
	public function updataMoodById($id,$data){
		if(!$id || !is_numeric($id)){
			throw_exception('ID不合法');
		}
		if(!$data || !is_array($data)){
			throw_exception('更新的数据不合法');
		}
		return $this->_db->where('id='.$id)->save($data);
	}
	
	public function getMoods($data,$page,$pageSize=10) {
		$data['status']=array('neq',-1);
		$offset = ($page-1)*$pageSize;
		$list = $this->_db->where($data)->order('id desc')->limit($offset,$pageSize)->select();
	    return $list;
	}
	
	public function getMoodsCount($data=array()){
		$data['status']=array('neq',-1);
		return $this->_db->where($data)->count();
	}
	
	public function updataStatusById($id,$status){
		if(!is_numeric($id) || !$id){
			throw_exception("ID不合法");
		}
		if(!is_numeric($status) || !$status){
			throw_exception("状态不合法");
		}
		$data['status']=$status;
		return $this->_db->where('id='.$id)->save($data);
	}
	
	public function find ($id)
	{
		if(!$id || !is_numeric($id)){
			return array();
		}
		return $this->_db->where('id='.$id)->find();
	}
	
	
}	